package com.ubaer.zsycz.ui.fragment;

import com.lsw.dialog.DialogProgress;
import com.lsw.util.LogUtils;
import com.lsw.util.ToastUtil;
import com.ubaer.zsycz.httpapi.HttpApi;
import com.ubaer.zsycz.inject.Constants;
import com.ubaer.zsycz.ui.base.presenter.BasePresenter;

import javax.inject.Inject;

import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/7/10 0010.
 */

public class UntreatedPresenter extends BasePresenter<UntreatedContract.View> implements UntreatedContract.Presenter {
    @Inject
    HttpApi httpApi;

    @Inject
    public UntreatedPresenter() {

    }

    @Override
    public void getOrderList(String status, String keyword, int page, String page_size) {
        DialogProgress progress = new DialogProgress(mContext);
        progress.show();
        Disposable disposable = httpApi
                .getOrderList(status, keyword, page + "", page_size)
                .subscribe(baseBean -> {
                    progress.dismiss();
                    mView.RefreshSucceed();
                    if (baseBean.getStatus() == Constants.CODE_SUCESS) {
                        mView.setOrderList(baseBean.getData(), baseBean.getData().size() >= Constants.PAGE_DEFAULT_COUNT);
                    } else if (baseBean.getStatus() == Constants.CODE_LOGIN) {
                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.openLogin();
                    } else {
                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                    }
                }, throwable -> {
                    mView.RefreshFail();
                    progress.dismiss();
                    LogUtils.e("TAG_Enroll", throwable.getMessage());
                    ToastUtil.showToast(mContext, throwable.getMessage());
                });
        mCompositeDisposable.add(disposable);
    }

    @Override
    public void ProcessingOrder(String id, String status, String reason) {
        DialogProgress progress = new DialogProgress(mContext);
        progress.show();
        Disposable disposable = httpApi
                .ProcessingOrder(id, status, reason)
                .subscribe(baseBean -> {
                    progress.dismiss();
                    if (baseBean.getStatus() == Constants.CODE_SUCESS) {
//                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.setProcessingSucceed();
                    } else if (baseBean.getStatus() == Constants.CODE_HANDLE) {
//                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.getRefresh();
                        mView.setProcessingfail(baseBean.getMessage().toString());
                    } else if (baseBean.getStatus() == Constants.CODE_LOGIN) {
                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.openLogin();
                    } else {
//                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.setProcessingfail(baseBean.getMessage().toString());
                    }
                }, throwable -> {
                    progress.dismiss();
                    LogUtils.e("TAG_Enroll", throwable.getMessage());
                    ToastUtil.showToast(mContext, throwable.getMessage());
                });
        mCompositeDisposable.add(disposable);
    }

    @Override
    public void ProcessingOrders(String ids) {
        LogUtils.i("lsw", "ids====" + ids);
        DialogProgress progress = new DialogProgress(mContext);
        progress.show();
        Disposable disposable = httpApi
                .ProcessingOrders(ids)
                .subscribe(baseBean -> {
                    progress.dismiss();
                    if (baseBean.getStatus() == Constants.CODE_SUCESS) {
                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.setProcessingSucceeds();
                    } else if (baseBean.getStatus() == Constants.CODE_LOGIN) {
                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.openLogin();
                    } else {
//                        ToastUtil.showToast(mContext, baseBean.getMessage().toString());
                        mView.setProcessingfail(baseBean.getMessage().toString());
                    }
                }, throwable -> {
                    progress.dismiss();
                    LogUtils.e("TAG_Enroll", throwable.getMessage());
                    ToastUtil.showToast(mContext, throwable.getMessage());
                });
        mCompositeDisposable.add(disposable);
    }


}
